package com.wang.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Classname CorsConfig
 * @Description TODO
 * @Date 2024/5/22 9:10
 * @Created by pc
 */
// @Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 针对的映射处理
        registry.addMapping("/**")
                // 新版本不支持该方法写*
                // .allowedOrigins("*")
                // 针对Origin 域名
                .allowedOriginPatterns("*")
                // 针对方法的
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                // 是否允许发送cookie
        .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
